using System;
using System.Collections.Generic;
using System.Text;
using NAnt.Core;
using CodePlex.SpaceBlock;
using CodePlex.SpaceBlock.Tasks;
using CodePlex.Resourceful;


namespace CodePlex.SpaceBlock.NAnt
{
    abstract public class BaseTask : Task
    {


        protected abstract GenericTask NewTask();





        private readonly GenericTask _task;

        public BaseTask()
        {
            _task = this.NewTask();

            _task.Message += delegate(object sender, MessageEventArgs e)
            {
                Level messageLevel = Level.None;

                if (e.Level == MessageLevel.Info)
                {
                    messageLevel = Level.Info;
                }
                if (e.Level == MessageLevel.Warning)
                {
                    messageLevel = Level.Warning;
                }
                if (e.Level == MessageLevel.Error)
                {
                    messageLevel = Level.Error;
                }

                this.Log(messageLevel, e.Message);
            };
        }


        

        protected string GetProperty(string name)
        {
            return _task.GetProperty(name);
        }

        public void SetProperty(string name, string value)
        {
            _task.SetProperty(name, value);
        }


        protected override void ExecuteTask()
        {

            
            bool rt = _task.Execute();

            if (!rt)
            {
                throw CodePlexException.Format("Task Failed.");
            }
        }
      
    }
}
